<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>webSocket</title>
  <script>
    // 1.创建链接
    const ws = new WebSocket('ws://47.94.46.113:7788/imserver/1')
    // 2.监听链接事件
    ws.addEventListener('open', openHandler);
    ws.addEventListener('close', closeHandler);
    ws.addEventListener('error', errorHandler);
    ws.addEventListener('message', messageHandler);

    function openHandler() {
      console.log('WebSocket open');
      // 向服务器端发送数据
      ws.send('hello Server');
    }

    function closeHandler() {
      console.log('WebSocket close');
    }

    function errorHandler() {
      console.log('WebSocket erroe');
    }

    function messageHandler(e) {
      // console.log('WebSocket message');
      console.log(e.data);
      console.log(e.origin);
    }
  </script>
</head>

<body>

</body>

</html>